package test.src.awt_swing;

import javax.swing.*;

public class CourseDemo {
    JFrame jFrame = new JFrame("Java课堂样例");

    Box vBox = Box.createVerticalBox();

    Box hBox1 = Box.createHorizontalBox();
    Box hBox2 = Box.createHorizontalBox();
    Box hBox3 = Box.createHorizontalBox();
    Box hBox4 = Box.createHorizontalBox();

    JLabel label11 = new JLabel("文本框：");
    JTextField textField12 = new JTextField(12);
    JLabel label13 = new JLabel("按钮：");
    JButton ok14 = new JButton("确定");

    JLabel label21 = new JLabel("选择框:");
    JCheckBox checkBox22 = new JCheckBox("喜欢音乐");
    JCheckBox checkBox23 = new JCheckBox("喜欢旅游");
    JCheckBox checkBox24 = new JCheckBox("喜欢篮球");

    JLabel label31 = new JLabel("单选按钮");
    JRadioButton male = new JRadioButton("男");
    JRadioButton female = new JRadioButton("女");
    JLabel label34 = new JLabel("下拉列表：");
    JComboBox<String> jComboBox = new JComboBox<>(new String[]{"音乐天地", "动感地带"});

    JLabel label41 = new JLabel("文本区:");
    JTextArea jtextArea = new JTextArea(6, 12);

    private void init() {
        //组装组件
        hBox1.add(label11);
        hBox1.add(textField12);
        hBox1.add(label13);
        hBox1.add(ok14);

        hBox2.add(label21);
        hBox2.add(checkBox22);
        hBox2.add(checkBox23);
        hBox2.add(checkBox24);

        hBox3.add(label31);
        hBox3.add(male);
        hBox3.add(female);
        ButtonGroup group = new ButtonGroup();
        group.add(male);
        group.add(female);
        hBox3.add(label34);
        hBox3.add(jComboBox);

        hBox4.add(label41);
        hBox4.add(jtextArea);

        vBox.add(hBox1);
        vBox.add(hBox2);
        vBox.add(hBox3);
        vBox.add(hBox4);

        jFrame.add(vBox);

        jFrame.pack();
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new CourseDemo().init();
    }
}
